<template>
  <div class="tag-manager">
    <h3>标签列表</h3>
    <div class="tag-list">
      <div 
        v-for="tag in videoStore.tags" 
        :key="tag.id" 
        class="tag-item"
        @click="jumpToTime(tag.start_time)"
      >
        <div class="tag-info">
          <div class="tag-description">{{ tag.description }}</div>
          <div class="tag-time">
            {{ formatTime(tag.start_time) }} - {{ formatTime(tag.end_time) }}
            <span class="tag-duration">({{ formatDuration(tag.end_time - tag.start_time) }})</span>
          </div>
        </div>
        <div class="tag-actions">
          <button class="edit-btn" @click.stop="$emit('edit-tag', tag)">编辑</button>
          <button class="delete-btn" @click.stop="deleteTag(tag.id)">删除</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useVideoStore } from '../stores/videoStore'
import { handleError, createErrorMessage } from '../../utils/error'
import { formatTime, formatDuration } from '../../utils/format'
import { PLAYER } from '../../constants/player'

const videoStore = useVideoStore()

const deleteTag = async (tagId) => {
  try {
    await videoStore.deleteTag(tagId)
  } catch (error) {
    console.error(createErrorMessage('删除标签', error))
  }
}

const jumpToTime = (time) => {
  videoStore.jumpToTime(time)
}
</script>

<style scoped>
.tag-manager {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

h3 {
  margin: 0 0 16px 0;
  color: #333;
}

.tag-list {
  flex: 1;
  overflow-y: auto;
}

.tag-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background-color 0.2s;
}

.tag-item:hover {
  background-color: #f5f5f5;
}

.tag-info {
  flex: 1;
  min-width: 0;
}

.tag-description {
  font-size: 14px;
  color: #333;
  margin-bottom: 4px;
  word-break: break-word;
}

.tag-time {
  font-size: 12px;
  color: #666;
}

.tag-duration {
  margin-left: 8px;
  color: #999;
}

.tag-actions {
  display: flex;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}

.tag-item:hover .tag-actions {
  opacity: 1;
}

.edit-btn,
.delete-btn {
  padding: 4px 8px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}

.edit-btn {
  background-color: #2196f3;
  color: white;
}

.edit-btn:hover {
  background-color: #1976d2;
}

.delete-btn {
  background-color: #f44336;
  color: white;
}

.delete-btn:hover {
  background-color: #d32f2f;
}
</style> 